
// pages/index/component/fundComponent/fundComponent.js
import{getInfo} from '../../../../api/foundation'
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info: {
      type: Object,
  }
  },

  /**
   * 组件的初始数据
   */
  data: {
      money:0,
      canshu:'',
  },

  /**
   * 组件的方法列表
   */
  lifetimes: {
    attached() {
      this.loadFund()
    }},
    pageLifetimes: {
      show: function () {
        this.loadFund()
      
      },
    },
  methods: {
    loadFund(){
      getInfo({mchId:app.globalData.mchId}).then(res=>{

        var number=Number(res.data.vip1)+Number(res.data.vip2)+Number(res.data.vip3)
        +Number(res.data.vip4)+Number(res.data.vip5)+Number(res.data.fund)+Number(res.data.atvy)
        +Number(res.data.bonus)
        var mathNumber=0
        if(number>0&&number<=100){
          mathNumber=10
        }else if(number>0&&number<=10&&number>0){
            mathNumber=4
        }else if(number>0&&number<=1000&&number>100){
          mathNumber=100
        }else if(number>0&&number<=1000000&&number>1000){
          mathNumber=1000
        }
        if(number>0){
          this.data.canshu=setInterval(()=>{
            this.data.money+=Math.ceil(Math.random()*mathNumber);  
            this.setData({
              money:this.data.money
            })
            if(this.data.money>=number){
              clearInterval(this.data.canshu)
              this.data.money=number
              this.setData({
                money:this.data.money
              })
            } 
          },40)
        }

      })
    },

  }
})
